using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.mail
{
[System.Serializable]
public  class SystemMail : Mail
 {

    public cfg.time.DateTimeRange timeRange  = new cfg.time.DateTimeRange();
     


    public const int TYPE_ID = 535781299;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(7);
        os.WriteSize(Tag.INT | (1 << Tag.TAG_SHIFT));  os.WriteInt(id);  
         os.WriteSize(Tag.STRING | (2 << Tag.TAG_SHIFT));  os.WriteString(title);  
         os.WriteSize(Tag.STRING | (3 << Tag.TAG_SHIFT));  os.WriteString(sender);  
         os.WriteSize(Tag.STRING | (4 << Tag.TAG_SHIFT));  os.WriteString(message);  
         os.WriteSize(Tag.INT | (5 << Tag.TAG_SHIFT));  os.WriteInt(deleteTime);  
         os.WriteSize(Tag.BEAN | (6 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_bonus_Bonus(reward,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.BEAN | (7 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_time_DateTimeRange(timeRange,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.INT | (1 << Tag.TAG_SHIFT)):   id = os.ReadInt(); break;  
             case (Tag.STRING | (2 << Tag.TAG_SHIFT)):   title = os.ReadString(); break;  
             case (Tag.STRING | (3 << Tag.TAG_SHIFT)):   sender = os.ReadString(); break;  
             case (Tag.STRING | (4 << Tag.TAG_SHIFT)):   message = os.ReadString(); break;  
             case (Tag.INT | (5 << Tag.TAG_SHIFT)):   deleteTime = os.ReadInt(); break;  
             case (Tag.BEAN | (6 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); reward = cfg.Extensions.unmarshal_compatible_cfg_bonus_Bonus(os); os = _oldOs; break; }   
             case (Tag.BEAN | (7 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); timeRange = cfg.Extensions.unmarshal_compatible_cfg_time_DateTimeRange(os); os = _oldOs; break; }   
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "SystemMail");
        ele.WriteStartElement("id"); ele.WriteAttributeString("id", "1"); ele.WriteInt(id); ele.WriteEndElement();
         ele.WriteStartElement("title"); ele.WriteAttributeString("id", "2"); ele.WriteString2(title); ele.WriteEndElement();
         ele.WriteStartElement("sender"); ele.WriteAttributeString("id", "3"); ele.WriteString2(sender); ele.WriteEndElement();
         ele.WriteStartElement("message"); ele.WriteAttributeString("id", "4"); ele.WriteString2(message); ele.WriteEndElement();
         ele.WriteStartElement("deleteTime"); ele.WriteAttributeString("id", "5"); ele.WriteInt(deleteTime); ele.WriteEndElement();
         ele.WriteStartElement("reward"); ele.WriteAttributeString("id", "6"); cfg.Extensions.xml_marshal_cfg_bonus_Bonus(reward,ele); ele.WriteEndElement();
         ele.WriteStartElement("timeRange"); ele.WriteAttributeString("id", "7"); cfg.Extensions.xml_marshal_cfg_time_DateTimeRange(timeRange,ele); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  id = ele.ReadInt(); break; 
                 case 2:  title = ele.ReadString2(); break; 
                 case 3:  sender = ele.ReadString2(); break; 
                 case 4:  message = ele.ReadString2(); break; 
                 case 5:  deleteTime = ele.ReadInt(); break; 
                 case 6:  reward = cfg.Extensions.xml_unmarshal_cfg_bonus_Bonus(ele); break; 
                 case 7:  timeRange = cfg.Extensions.xml_unmarshal_cfg_time_DateTimeRange(ele); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "id":  id = ele.ReadInt(); break; 
                 case "title":  title = ele.ReadString2(); break; 
                 case "sender":  sender = ele.ReadString2(); break; 
                 case "message":  message = ele.ReadString2(); break; 
                 case "delete_time":  deleteTime = ele.ReadInt(); break; 
                 case "reward":  reward = cfg.Extensions.xml_unmarshal_cfg_bonus_Bonus(ele); break; 
                 case "time_range":  timeRange = cfg.Extensions.xml_unmarshal_cfg_time_DateTimeRange(ele); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
